package com.example.bms.order.controller;

import java.util.Arrays;
import java.util.Map;

import com.example.bms.order.feign.Storehousefeign;
import com.example.bms.order.feign.Userfeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.example.bms.order.entity.PurchaseEntity;
import com.example.bms.order.service.PurchaseService;
import com.example.common.utils.PageUtils;
import com.example.common.utils.R;

import javax.annotation.Resource;


/**
 * @author Jiang
 * @email 337262603@qq.com
 * @date 2022-01-29 23:12:38
 */
@RestController
@RequestMapping("order/purchase")
@CrossOrigin
public class PurchaseController {
    @Autowired
    private PurchaseService purchaseService;

    @Resource
    private Userfeign userfeign;

    @Resource
    private Storehousefeign storehousefeign;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("order:purchase:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = purchaseService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{phid}")
    //@RequiresPermissions("order:purchase:info")
    public R info(@PathVariable("phid") String phid) {
        PurchaseEntity purchase = purchaseService.getById(phid);

        return R.ok().put("purchase", purchase);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("order:purchase:save")
    public R save(@RequestBody PurchaseEntity purchase) {
        purchaseService.save(purchase);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("order:purchase:update")
    public R update(@RequestBody PurchaseEntity purchase) {
        purchaseService.updateById(purchase);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("order:purchase:delete")
    public R delete(@RequestBody String[] phids) {
        purchaseService.removeByIds(Arrays.asList(phids));

        return R.ok();
    }

    @RequestMapping("/stafflist")
    public R stafflist(@RequestParam Map<String, Object> params) {
        return userfeign.stafflist(params);
    }

    @RequestMapping("/waterlist")
    public R waterlist(@RequestParam Map<String, Object> params) {
        return storehousefeign.waterlist(params);
    }

    @RequestMapping("/providerlist")
    public R providerlist(@RequestParam Map<String, Object> params) {
        return storehousefeign.providerlist(params);
    }

    @RequestMapping("/storehouselist")
    public R storehouselist(@RequestParam Map<String, Object> params) {
        return storehousefeign.storehouselist(params);
    }
}
